/**
 * Copyright (c) 2019-2029, wwww.kiwipeach.cn (liuburu@qq.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * https://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package cn.kiwipeach.blog.service.impl;

import cn.kiwipeach.blog.domain.AccessTokenVO;
import cn.kiwipeach.blog.exception.BlogException;
import cn.kiwipeach.blog.service.IAccessTokenService;
import lombok.extern.slf4j.Slf4j;
import open.kiwipeach.autoconfigure.shiro.token.AccessToken;
import open.kiwipeach.autoconfigure.web.utils.JwtTokenUtil;
import org.springframework.stereotype.Service;

/**
 * 描述：用户访问token服务实现类
 *
 * @author kiwipeach
 * @since 2.0
 */
@Service
@Slf4j
public class AccessTokenServiceImpl implements IAccessTokenService {


    @Override
    public AccessTokenVO cacheStoreToken(AccessToken accessToken) {
        log.warn("cacheStoreToken中的类加载器:{}", getClass().getClassLoader());
        return new AccessTokenVO(accessToken.getToken(), accessToken.getExpiresTime(), accessToken.getRefreshToken());
    }

    @Override
    public AccessTokenVO getAccessToken(String userId, String refreshToken) {
        throw new BlogException("-ACCESS-TOKEN-01", "token已失效");
    }

    @Override
    public AccessTokenVO refreshToken(String refreshToken, AccessToken newAccessToken) {
        return JwtTokenUtil.signToken(newAccessToken);
    }

    @Override
    public Boolean removeToken(AccessToken accessToken) {
        return true;
    }

}
